From afedb1e48fe477fb8ae2e13387f5a467fd912884 Mon Sep 17 00:00:00 2001 From: "mjw@wray-m-3.hpl.hp.com" Date: Wed, 16 Mar 2005 16:48:49 +0000 Subject: [PATCH] bitkeeper revision 1.1159.269.5 (42386371nvHctvk3SHgDUG4w3o9URw) Add support for specifying the interface name to be used by a netif backend driver instead of the default vifD.N. Signed-off-by: Mike Wray --- .../drivers/xen/netback/interface.c | 8 ++++-- tools/python/xen/lowlevel/xu/xu.c | 26 +++++++++++++++++++ tools/python/xen/xend/server/netif.py | 16 +++++++++--- tools/python/xen/xm/create.py | 10 +++++-- xen/include/public/io/domain_controller.h | 5 ++-- 5 files changed, 56 insertions(+), 9 deletions(-) diff --git a/linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c b/linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c index 9a3eea5932..f54dd0ad9c 100644 --- a/linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c +++ b/linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c @@ -119,9 +119,13 @@ void netif_create(netif_be_create_t *create) unsigned int handle = create->netif_handle; struct net_device *dev; netif_t **pnetif, *netif; - char name[IFNAMSIZ]; + char name[IFNAMSIZ] = {}; - snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle); + if(create->vifname[0] == '\0'){ + snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle); + } else { + snprintf(name, IFNAMSIZ - 1, "%s", create->vifname); + } dev = alloc_netdev(sizeof(netif_t), name, ether_setup); if ( dev == NULL ) { diff --git a/tools/python/xen/lowlevel/xu/xu.c b/tools/python/xen/lowlevel/xu/xu.c index 9a67693683..3f32cadc34 100644 --- a/tools/python/xen/lowlevel/xu/xu.c +++ b/tools/python/xen/lowlevel/xu/xu.c @@ -259,6 +259,7 @@ static PyTypeObject xu_notifier_type = { */ #define TYPE(_x,_y) (((_x)<<8)|(_y)) + #define P2C(_struct, _field, _ctype) \ do { \ PyObject *obj; \ @@ -279,6 +280,29 @@ static PyTypeObject xu_notifier_type = { } \ xum->msg.length = sizeof(_struct); \ } while ( 0 ) + +/** Set a char[] field in a struct from a Python string. + * Can't do this in P2C because of the typing. + */ +#define P2CSTRING(_struct, _field) \ + do { \ + PyObject *obj; \ + if ( (obj = PyDict_GetItemString(payload, #_field)) != NULL ) \ + { \ + if ( PyString_Check(obj) ) \ + { \ + _struct * _cobj = (_struct *)&xum->msg.msg[0]; \ + int _field_n = sizeof(_cobj->_field); \ + memset(_cobj->_field, 0, _field_n); \ + strncpy(_cobj->_field, \ + PyString_AsString(obj), \ + _field_n - 1); \ + dict_items_parsed++; \ + } \ + } \ + xum->msg.length = sizeof(_struct); \ + } while ( 0 ) + #define C2P(_struct, _field, _pytype, _ctype) \ do { \ PyObject *obj = Py ## _pytype ## _From ## _ctype \ @@ -456,6 +480,7 @@ static PyObject *xu_message_get_payload(PyObject *self, PyObject *args) C2P(netif_be_create_t, domid, Int, Long); C2P(netif_be_create_t, netif_handle, Int, Long); C2P(netif_be_create_t, status, Int, Long); + C2P(netif_be_create_t, vifname, String, String); return dict; case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY): C2P(netif_be_destroy_t, domid, Int, Long); @@ -623,6 +648,7 @@ static PyObject *xu_message_new(PyObject *self, PyObject *args) P2C(netif_be_create_t, mac[3], u8); P2C(netif_be_create_t, mac[4], u8); P2C(netif_be_create_t, mac[5], u8); + P2CSTRING(netif_be_create_t, vifname); break; case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY): P2C(netif_be_destroy_t, domid, u32); diff --git a/tools/python/xen/xend/server/netif.py b/tools/python/xen/xend/server/netif.py index 753ae29972..5afb3df388 100755 --- a/tools/python/xen/xend/server/netif.py +++ b/tools/python/xen/xend/server/netif.py @@ -130,7 +130,13 @@ class NetDev(controller.SplitDev): self.bridge = None self.script = None self.ipaddr = [] + self.vifname = None + self.vifname = sxp.child_value(config, 'vifname') + if self.vifname is None: + self.vifname = "vif%d.%d" % (self.controller.dom, self.vif) + if len(self.vifname) > 15: + raise XendError('invalid vifname: too long: ' + self.vifname) mac = self._get_config_mac(config) if mac is None: raise XendError("invalid mac") @@ -189,7 +195,9 @@ class NetDev(controller.SplitDev): val = ['vif', ['idx', self.idx], ['vif', vif], - ['mac', mac]] + ['mac', mac], + ['vifname', self.vifname], + ] if self.bridge: val.append(['bridge', self.bridge]) if self.script: @@ -207,7 +215,7 @@ class NetDev(controller.SplitDev): def get_vifname(self): """Get the virtual interface device name. """ - return "vif%d.%d" % (self.controller.dom, self.vif) + return self.vifname def get_mac(self): """Get the MAC address as a string. @@ -267,7 +275,9 @@ class NetDev(controller.SplitDev): msg = packMsg('netif_be_create_t', { 'domid' : self.controller.dom, 'netif_handle' : self.vif, - 'mac' : self.mac }) + 'mac' : self.mac, + 'vifname' : self.vifname + }) self.getBackendInterface().writeRequest(msg, response=d) return d diff --git a/tools/python/xen/xm/create.py b/tools/python/xen/xm/create.py index 03f815eddb..ae023e49f5 100644 --- a/tools/python/xen/xm/create.py +++ b/tools/python/xen/xm/create.py @@ -151,7 +151,7 @@ gopts.var('ipaddr', val="IPADDR", fn=append_value, default=[], use="Add an IP address to the domain.") -gopts.var('vif', val="mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM", +gopts.var('vif', val="mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM,vifname=NAME", fn=append_value, default=[], use="""Add a network interface with the given MAC address and bridge. The vif is configured by calling the given configuration script. @@ -159,6 +159,8 @@ gopts.var('vif', val="mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM", If bridge is not specified the default bridge is used. If script is not specified the default script is used. If backend is not specified the default backend driver domain is used. + If vifname is not specified the backend virtual interface will have name vifD.N + where D is the domain id and N is the interface id. This option may be repeated to add more than one vif. Specifying vifs will increase the number of interfaces as needed.""") @@ -289,14 +291,18 @@ def configure_vifs(config_devs, vals): script = d.get('script') backend = d.get('backend') ip = d.get('ip') + vifname = d.get('vifname') else: mac = randomMAC() bridge = None script = None backend = None ip = None + vifname = None config_vif = ['vif'] config_vif.append(['mac', mac]) + if vifname: + config_vif.append(['vifname', vifname]) if bridge: config_vif.append(['bridge', bridge]) if script: @@ -383,7 +389,7 @@ def preprocess_vifs(opts, vals): (k, v) = b.strip().split('=', 1) k = k.strip() v = v.strip() - if k not in ['mac', 'bridge', 'script', 'backend', 'ip']: + if k not in ['mac', 'bridge', 'script', 'backend', 'ip', 'vifname']: opts.err('Invalid vif specifier: ' + vif) d[k] = v vifs.append(d) diff --git a/xen/include/public/io/domain_controller.h b/xen/include/public/io/domain_controller.h index 61ba2d3776..c706ab016e 100644 --- a/xen/include/public/io/domain_controller.h +++ b/xen/include/public/io/domain_controller.h @@ -477,9 +477,10 @@ typedef struct { u32 netif_handle; /* 4: Domain-specific interface handle. */ u8 mac[6]; /* 8 */ u16 __pad1; /* 14 */ + char vifname[16]; /* 16 */ /* OUT */ - u32 status; /* 16 */ -} PACKED netif_be_create_t; /* 20 bytes */ + u32 status; /* 32 */ +} PACKED netif_be_create_t; /* 36 bytes */ /* * CMSG_NETIF_BE_DESTROY: -- 2.30.2